setwd("c:/test/Cousera/")

pollutantmean <- function(directory, pollutant, id = 1:332) {
  dataall <- data.frame()
  filename <- list.files(directory, full.names=TRUE)[id]
  for (x in filename) {
    tdata <- read.csv(x, header = TRUE)
    dataall <- rbind(dataall, tdata)
  }
  pollutantmean <- mean(dataall[,pollutant], na.rm = TRUE)
  pollutantmean
}


pollutantmean("specdata", "sulfate", 1:10)
pollutantmean("specdata", "nitrate", 70:72)
pollutantmean("specdata", "nitrate", 23)